import { defineMock } from "./base";
import { createReadStream, statSync } from "node:fs";

export default defineMock([
  {
    url: "/menu.json",
    type: "menu.json",
    response(req, res) {
      res.setHeader("Content-Type", "application/json");
      res.setHeader("Content-Disposition", "attachment; filename=menu.json");
      res.setHeader("Content-Length", statSync("./mock/files/menu.json").size);
      createReadStream("./mock/files/menu.json").pipe(res);
    },
  },
  {
    url: "/hmiconfig.json",
    type: "hmiconfig.json",
    response(req, res) {
      res.setHeader("Content-Type", "application/json");
      res.setHeader("Content-Disposition", "attachment; filename=hmiconfig.json");
      res.setHeader("Content-Length", statSync("./mock/files/hmiconfig.json").size);
      createReadStream("./mock/files/hmiconfig.json").pipe(res);
    },
  },
  {
    url: "hmi/config/menu",
    type: "menu.json",
    response(req, res) {
      res.setHeader("Content-Type", "application/json");
      res.setHeader("Content-Disposition", "attachment; filename=menu.json");
      res.setHeader("Content-Length", statSync("./mock/files/menu.json").size);
      createReadStream("./mock/files/menu.json").pipe(res);
    },
  },

  {
    // 设置 response.config.responseType === "blob"
    url: "hmi/config/table-header-rule",
    type: "hmiconfig.json",
    response(req, res) {
      res.setHeader("Content-Type", "application/json");
      res.setHeader("Content-Disposition", "attachment; filename=hmiconfig.json");
      res.setHeader("Content-Length", statSync("./mock/files/hmiconfig.json").size);
      createReadStream("./mock/files/hmiconfig.json").pipe(res);
    },
  },
]);

// 文件mock
